CMAKE_MINIMUM_REQUIRED( VERSION 2.6 )

PROJECT( sceneExpression )

# SET( CMAKE_CONFIGURATION_TYPES "Release" CACHE INTERNAL "Build Type" FORCE )
# SET( CMAKE_BUILD_TYPE Debug CACHE STRING "Options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE )

# hide a few options from "simple view" in the gui
MARK_AS_ADVANCED( CMAKE_CONFIGURATION_TYPES )
MARK_AS_ADVANCED( CMAKE_BUILD_TYPE )
MARK_AS_ADVANCED( CMAKE_OSX_ARCHITECTURES )
MARK_AS_ADVANCED( CMAKE_INSTALL_PREFIX )
MARK_AS_ADVANCED( CMAKE_OSX_SYSROOT )


ADD_DEFINITIONS(-DOSG_LIBRARY_STATIC)
# ADD_DEFINITIONS(-pedantic -fvisibility=hidden)
IF(UNIX)
	ADD_DEFINITIONS(-Wall -Wparentheses -Wno-long-long -Wno-import -pedantic -Wreturn-type -Wmissing-braces -Wunknown-pragmas -Wunused)
ENDIF()


SET( SX_HEADER_DIRECTORY  ${PROJECT_SOURCE_DIR}/libs/sx/include )
SET( SX_SOURCE_DIRECTORY  ${PROJECT_SOURCE_DIR}/libs/sx/src )
SET( SX_BINARY_DIRECTORY  ${PROJECT_SOURCE_DIR}/libs/sx/bin )


# include directory for SceneExpression
INCLUDE_DIRECTORIES( ${SX_HEADER_DIRECTORY} )


# ------------ Platform specifics
IF(UNIX)
IF(APPLE)
	# OSX
	
	# Set SDK
	#
	SET( CMAKE_OSX_SYSROOT  "/Developer/SDKs/MacOSX10.5.sdk" )
	# match visibility of osg, a warning issue
	SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.5 -ftree-vectorize -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE)

	
	# Find osx frameworks
	#
	INCLUDE_DIRECTORIES( /Developer/Headers/FlatCarbon )
	FIND_LIBRARY(AGL_LIBRARY AGL)
	FIND_LIBRARY(APP_SERVICES_LIBRARY ApplicationServices )
	FIND_LIBRARY(ATBOX_LIBRARY AudioToolbox)
	FIND_LIBRARY(CARBON_LIBRARY Carbon)
	FIND_LIBRARY(CAUDIO_LIBRARY CoreAudio)
	FIND_LIBRARY(CFOUNDATION_LIBRARY CoreFoundation)
	FIND_LIBRARY(CSERVICES_LIBRARY CoreServices)
	FIND_LIBRARY(OPENGL_LIBRARY OpenGL)
	FIND_LIBRARY(QUICKTIME_LIBRARY QuickTime )
	FIND_LIBRARY(IOKIT_LIBRARY IOKit )
	
	MARK_AS_ADVANCED (AGL_LIBRARY
			 APP_SERVICES_LIBRARY
			 ATBOX_LIBRARY
			 CARBON_LIBRARY
			 CAUDIO_LIBRARY
			 CFOUNDATION_LIBRARY
			 CSERVICES_LIBRARY
			 OPENGL_LIBRARY
			 QUICKTIME_LIBRARY
			 IOKIT_LIBRARY)
	SET(OSX_FRAMEWORKS ${AGL_LIBRARY} 
	                   ${APP_SERVICES_LIBRARY} 
	                   ${ATBOX_LIBRARY} 
	                   ${CARBON_LIBRARY} 
	                   ${CAUDIO_LIBRARY} 
	                   ${CFOUNDATION_LIBRARY} 
	                   ${CSERVICES_LIBRARY} 
	                   ${OPENGL_LIBRARY} 
	                   ${QUICKTIME_LIBRARY}
					   ${IOKIT_LIBRARY})
	
	
	# set the executable to build
	#
	SET(EXECUTABLE_TYPE MACOSX_BUNDLE)
	
	# include directory for OSG
	INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/libs/osg-osx/include )
		
	# set common target libs for apps
	#
	SET( TARGET_LINK_LIBRARIES
		${OSX_FRAMEWORKS}
		${PROJECT_SOURCE_DIR}/libs/freetype-osx/lib/freetype.a	
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgViewer.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgdb_freetype.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgdb_qt.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgdb_bmp.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgdb_osg.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgdb_obj.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgdb_3ds.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgdb_dxf.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgdb_stl.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgGA.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgText.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgDB.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgUtil.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosg.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libOpenThreads.a		
	)




ELSE()
	# Linux
	
	FIND_PACKAGE(X11)
	FIND_PACKAGE(OpenGL)
	# FIND_PACKAGE(FreeType)
	FIND_PACKAGE(ZLIB)
    # FIND_PACKAGE(GIFLIB)
    FIND_PACKAGE(JPEG)
    FIND_PACKAGE(PNG)
    # FIND_PACKAGE(TIFF)
	SET( LINUX_TARGET_LIBRARIES  
		${X11_LIBRARY}
		${OpenGL_LIBRARY}
		${ZLIB_LIBRARY}
		${JPEG_LIBRARY}
		${PNG_LIBRARY}
	)
	
	# include directory for OSG
	INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/libs/osg-linux/include )
		
	# set common target libs for apps
	#
	SET( TARGET_LINK_LIBRARIES
		pthread m GL GLU SM ICE X11 Xext Xrandr z freetype jpeg png
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgViewer.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_freetype.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_png.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_jpeg.a
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_bmp.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_osg.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_obj.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_3ds.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_dxf.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_stl.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgGA.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgText.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgDB.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgUtil.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosg.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libOpenThreads.a	
	)
ENDIF(APPLE)
ENDIF(UNIX)



IF(WIN32)
	# Windows

	# FIND_PACKAGE(OpenGL)
	# FIND_PACKAGE(FreeType)
    # FIND_PACKAGE(JPEG)
    # FIND_PACKAGE(PNG)
	# FIND_PACKAGE(ZLIB)	
	# FIND_PACKAGE(QuickTime)
	
	# include directory for OSG
	INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/libs/osg-win32/include )	
	
	# set common target libs for apps
	#
	SET( TARGET_LINK_LIBRARIES 
		OpenGL32.lib GLu32.lib kernel32.lib setupapi.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib
		${PROJECT_SOURCE_DIR}/libs/freetype-win32/lib/freetype237.lib	
		${PROJECT_SOURCE_DIR}/libs/jpeg-win32/lib/libjpeg.lib
		${PROJECT_SOURCE_DIR}/libs/png-win32/lib/libpng12_static.lib
		${PROJECT_SOURCE_DIR}/libs/zlib-win32/lib/zlib.lib
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osg55-osgViewer.lib
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_freetype.lib
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_png.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_jpeg.lib
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_bmp.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_osg.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_obj.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_3ds.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_dxf.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_stl.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osg55-osgGA.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osg55-osgText.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osg55-osgDB.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osg55-osgUtil.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osg55-osg.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/ot11-OpenThreads.lib	
	)
	
	SET( ZLIB_DLL_RUNTIME  ${PROJECT_SOURCE_DIR}/libs/zlib-win32/bin/zlib1.dll )
	SET( PNG_DLL_RUNTIME  ${PROJECT_SOURCE_DIR}/libs/png-win32/bin/libpng13.dll )	
ENDIF()
# ------------ end platform specifics



MACRO( POST_BUILD_COPY_FILE  source_file  target_path )
	ADD_CUSTOM_COMMAND( 
		TARGET ${EXAMPLE_NAME}
	    POST_BUILD
	    COMMAND ${CMAKE_COMMAND} -E copy
		${source_file}
	    ${target_path}
	)
ENDMACRO()



###########################################
# LIBS
###########################################

# ----------------------------------------< sceneExpression >
ADD_LIBRARY( sx STATIC
    ${SX_HEADER_DIRECTORY}/sx/App.h
    ${SX_HEADER_DIRECTORY}/sx/BoxShape.h
    ${SX_HEADER_DIRECTORY}/sx/ButtonWidget.h
    ${SX_HEADER_DIRECTORY}/sx/Constants.h
    ${SX_HEADER_DIRECTORY}/sx/CircleShape.h
    ${SX_HEADER_DIRECTORY}/sx/EllipseShape.h
    ${SX_HEADER_DIRECTORY}/sx/EventHandlers.h
    ${SX_HEADER_DIRECTORY}/sx/GuiEvents.h
    ${SX_HEADER_DIRECTORY}/sx/ImageShape.h
    ${SX_HEADER_DIRECTORY}/sx/Key.h
    ${SX_HEADER_DIRECTORY}/sx/LineShape.h
    ${SX_HEADER_DIRECTORY}/sx/Main.h
    ${SX_HEADER_DIRECTORY}/sx/Model.h
    ${SX_HEADER_DIRECTORY}/sx/MonsterShape.h
    ${SX_HEADER_DIRECTORY}/sx/Mouse.h
    ${SX_HEADER_DIRECTORY}/sx/Node.h
    ${SX_HEADER_DIRECTORY}/sx/PanelWidget.h
    ${SX_HEADER_DIRECTORY}/sx/Pen.h
    ${SX_HEADER_DIRECTORY}/sx/RectangleShape.h
    ${SX_HEADER_DIRECTORY}/sx/Scene.h
    ${SX_HEADER_DIRECTORY}/sx/Shape.h
    ${SX_HEADER_DIRECTORY}/sx/SliderWidget.h
    ${SX_HEADER_DIRECTORY}/sx/TextShape.h
    ${SX_HEADER_DIRECTORY}/sx/TextureGeometry.h
    ${SX_HEADER_DIRECTORY}/sx/ToggleWidget.h
    ${SX_HEADER_DIRECTORY}/sx/Touch.h
    ${SX_HEADER_DIRECTORY}/sx/TouchShape.h    
    ${SX_HEADER_DIRECTORY}/sx/TriangleShape.h
    ${SX_HEADER_DIRECTORY}/sx/Types.h
    ${SX_HEADER_DIRECTORY}/sx/VertexGeometry.h
    ${SX_HEADER_DIRECTORY}/sx/VertexShape.h
    ${SX_HEADER_DIRECTORY}/sx/Visitors.h
    ${SX_HEADER_DIRECTORY}/sx/Widget.h

    ${SX_SOURCE_DIRECTORY}/App.cpp
    ${SX_SOURCE_DIRECTORY}/ButtonWidget.cpp
    ${SX_SOURCE_DIRECTORY}/CircleShape.cpp
    ${SX_SOURCE_DIRECTORY}/EllipseShape.cpp
    ${SX_SOURCE_DIRECTORY}/GuiEvents.cpp
    ${SX_SOURCE_DIRECTORY}/ImageShape.cpp
    ${SX_SOURCE_DIRECTORY}/LineShape.cpp
    ${SX_SOURCE_DIRECTORY}/Model.cpp
    ${SX_SOURCE_DIRECTORY}/MonsterShape.cpp
    ${SX_SOURCE_DIRECTORY}/Node.cpp
    ${SX_SOURCE_DIRECTORY}/PanelWidget.cpp
    ${SX_SOURCE_DIRECTORY}/RectangleShape.cpp
    ${SX_SOURCE_DIRECTORY}/Scene.cpp
    ${SX_SOURCE_DIRECTORY}/SliderWidget.cpp
    ${SX_SOURCE_DIRECTORY}/TextShape.cpp
    ${SX_SOURCE_DIRECTORY}/TextureGeometry.cpp
    ${SX_SOURCE_DIRECTORY}/ToggleWidget.cpp
    ${SX_SOURCE_DIRECTORY}/TouchShape.cpp    
    ${SX_SOURCE_DIRECTORY}/TriangleShape.cpp
    ${SX_SOURCE_DIRECTORY}/VertexGeometry.cpp
    ${SX_SOURCE_DIRECTORY}/VertexShape.cpp
    ${SX_SOURCE_DIRECTORY}/Visitors.cpp
    ${SX_SOURCE_DIRECTORY}/Widget.cpp

)


SET_TARGET_PROPERTIES( sx PROPERTIES 
	ARCHIVE_OUTPUT_DIRECTORY  ${SX_BINARY_DIRECTORY}
)
# ----------------------------------------</ sceneExpression >



###########################################
# ADDONS
###########################################

OPTION( BUILD_ADDON_SX_TOUCHKIT "Build the sxTouchkit addon." ON)
IF( BUILD_ADDON_SX_TOUCHKIT )
	ADD_SUBDIRECTORY( addons/sxOpencv )
	ADD_SUBDIRECTORY( addons/sxTouchkit )
ENDIF()

IF(APPLE)
	OPTION( BUILD_ADDON_SX_MULTIPAD "Build the sxMultipad addon." ON)
	IF( BUILD_ADDON_SX_MULTIPAD )
		ADD_SUBDIRECTORY( addons/sxMultipad )
	ENDIF()
ENDIF()

OPTION( BUILD_ADDON_SX_MICE "Build the sxMice addon." ON)
IF( BUILD_ADDON_SX_MICE )
	ADD_SUBDIRECTORY( addons/sxMice )
ENDIF()



###########################################
# EXAMPLES
###########################################

OPTION( BUILD_EXAMPLES "Build the stock examples." ON)
IF( BUILD_EXAMPLES )
	IF( BUILD_ADDON_SX_TOUCHKIT )
		ADD_SUBDIRECTORY( apps/addonExamples/touchkitSimpleExample )
	ENDIF()

	IF( BUILD_ADDON_SX_MULTIPAD )
		ADD_SUBDIRECTORY( apps/addonExamples/multipadExample )
	ENDIF()

	IF( BUILD_ADDON_SX_MICE )
		ADD_SUBDIRECTORY( apps/addonExamples/miceExample )
	ENDIF()

	ADD_SUBDIRECTORY( apps/examples/keymouseExample )
	ADD_SUBDIRECTORY( apps/examples/shapesExample )
	ADD_SUBDIRECTORY( apps/examples/widgetExample )
ENDIF()



###########################################
# APPS
###########################################

# List application directories here. E.g: 
# ADD_SUBDIRECTORY( apps/myApps/myFirstApp )


